<#-- 包含其他文件的内容 -->
<#include "../common/header.ftl"/>
<script>
    $(function () {
        // 查询指定文章
        $(".showContentBtn").click(function () {
            // 发送ajax请求获取文章的内容
            $.get("/travel/getContentById.do", {id: $(this).data("id")}, function (data) {
                // console.log(data.travelContent.content);
                $("#showContentModal .modal-body").html(data.travelContent.content);
            });
            $("#showContentModal").modal("show");
        });

        // 取消发布
        $(".changeStateBtn").click(function () {
            // 获取id和状态
            var id = $(this).data("id");
            var state = $(this).data("state");
            // 发送ajax请求
            $.get("/travel/updateState.do", {"id": id, "state": state}, function (data) {
                doSuccess(data);
            });
        });

        // 设置推荐
        $(".hotBtn").click(function () {
            // 时间插件
            laydate.render({
                elem: '#time' //指定元素
            });
            // 清空模态框
            $("#editForm").get(0).reset();
            // 获取json数据
            var josn = $(this).data("json");
            console.log(josn);
            // 将数据设置到模态框中
            if (josn) {
                $("#editForm input[name='travel.id']").val(josn.id);
                $("#editForm input[name='title']").val(josn.title);
                $("#editForm input[name='coverUrl']").val(josn.coverUrl);
                $("#coverUrl").attr("src", josn.coverUrl);
            }
            // 显示模态框
            $("#hotModal").modal("show");
        });

        // 提交游记推荐表单
        submitForm(".submitBtn", "#editForm");
        // 更换封面
        updateImg(".changeBtn");
    });

</script>
</head>
<body>

<!--图片上传表单-->
<#include "../common/img.ftl"/>


<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="releaseList"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布游记管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travel/releaseList.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>地点</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>

                <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td>${entity.title}</td>
                        <td>
                            <img src="${entity.coverUrl}" width="80px"/>
                        </td>
                        <td>${(entity.place.name)!}</td>
                        <td>${(entity.author.nickName)!}</td>
                        <td>${(entity.releaseTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                        <td>${entity.stateName}</td>
                        <td>
                            <a class="btn btn-info btn-xs showContentBtn" data-id="${entity.id}">
                                <span class="glyphicon glyphicon-pencil"></span> 查看文章
                            </a>
                            <a class="btn btn-danger btn-xs changeStateBtn" data-id="${entity.id}" data-state="1">
                                <span class="glyphicon glyphicon-pencil"></span> 取消发布
                            </a>
                            <a class="btn btn-danger btn-xs hotBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 推荐
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>


<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="showContentModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">查看</h4>
            </div>
            <div class="modal-body">
            </div>
            <div class="modal-footer">
            </div>
        </div>
    </div>
</div>

<!-- 模态框必须作为body的子标签 -->
<div class="modal fade" id="hotModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">推荐</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm">
                    <!--关联的游记id-->
                    <input type="text" name="travel.id" hidden>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="100%" class="changeBtn"/>
                            <a style="margin-left: 75px" class="btn btn-info glyphicon glyphicon-picture changeBtn"> 更换封面</a>
                            <input type="hidden" class="form-control" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" id="time" class="form-control" name="schedule">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select class="form-control" name="type">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>


<style>
    #showContentModal img {
        width: 100%
    }
</style>

</body>
</html>